<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>登录</title>
    <link rel="stylesheet" href="./css/base.css" />
    <link rel="stylesheet" href="./iconfont/iconfont.css" />
    <link rel="stylesheet" href="./css/login.css" />
  </head>
  <style type="text/css">
    .tips {
      padding: 4px 10px;
      color: #fff;
      border-radius: 2px;
      font-size: 16px;
      background-color: rgba(0, 0, 0, 0.5);
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      display: none;
      width: fit-content;
      white-space: nowrap;
    }
    #app{
      width: 100%;
      height: 100vh;
      overflow: hidden;
    }
  </style>
  <body>
    <div id="app">
    <div class="logo">
      <img src="./img/Logo.png" alt="" />
    </div>
    <div class="inp">
      <div>
        <span class="iconfont icon-yonghu"></span>
        <input type="text" placeholder="输入账号" name="number" />
      </div>
      <div>
        <span class="iconfont icon-mima"></span>
        <input type="text" placeholder="输入密码" name="password" />
      </div>
    </div>
    <button id="logOn">登 录</button>
    <p class="copyright">德龙农业版权所有</p>

    <!-- tips-->
    <div class="tips">
      <p>文本</p>
    </div>
  </div>
  </body>
  <script src="./js/jquery-3.7.1.min.js"></script>
  <script type="text/javascript" src="./js/request.js"></script>
  <script type="text/javascript">
    $(document).ready(function () {
      // 账号密码登录
      var throttledFunction = throttle(function () {
        var number = $('input[name="number"]').val();
        var password = $('input[name="password"]').val();
        if (number && password) {
          $.post(
            baseUrl + "/user.user/login",
            {
              account: number,
              password: password,
              app_id: 10001,
            },
            function (status) {
              if (status.code == 1) {
                tips("登录成功");
                // window.location.href =
                // status.data.token =
                console.log(status.data.token);
                sessionStorage.setItem("token", status.data.token);
                Orderstatus(status.data.token);
              } else {
                tips("账号或密码错误，请重新输入");
              }
              console.log(status);
            }
          );
        } else {
          tips("请输入账号或密码");
        }
      }, 500);
      // 点击
      $("#logOn").click(() => {
        throttledFunction();
      });

      // 轻提示
      function tips(text, time = 3000) {
        let tips = $(".tips");
        tips.html(text);
        tips.fadeToggle();
        setTimeout(() => {
          tips.fadeToggle("slow");
        }, time);
      }

      // 节流
      function throttle(func, wait) {
        var context, args, timeout;
        return function () {
          context = this;
          args = arguments;
          if (!timeout) {
            timeout = setTimeout(function () {
              func.apply(context, args);
              timeout = null;
            }, wait);
          }
        };
      }

      //获取下单状态
      function Orderstatus(token) {
        $.post(
          baseUrl + "/user.order/getInfo",
          {
            app_id: 10001,
            token: token,
          },
          function (result) {
            console.log(result);
            if (result.data.pay_status == "") {
              // console.log(result.data.pay_status);
              window.location.href = "submit.html";
            } else if (result.data.pay_status.value == 10) {
              // console.log(result.data.pay_status.value);
              window.location.href = "Information.html";
            } else if (result.data.pay_status.value == 20) {
              // console.log(result.data.pay_status.value);
              window.location.href = "inquire.html";
            }
          }
        );
      }
      const token = sessionStorage.getItem("token");
      if(token){
        console.log(111);
        Orderstatus(token);
      }
    
      
      });
  </script>
</html>
